package com.lancoo.edu.platform.operation.backupRestore.constant;

import com.lancoo.edu.platform.operation.backupRestore.strategy.backupRestore.BackupRestoreStrategy;
import com.lancoo.edu.platform.operation.backupRestore.strategy.backupRestore.imp.DmBackupRestoreStrategy;
import com.lancoo.edu.platform.operation.backupRestore.strategy.backupRestore.imp.MysqlBackupRestoreStrategy;
import com.lancoo.edu.platform.operation.backupRestore.strategy.backupRestore.imp.OceanBaseBackupRestoreStrategy;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author zhang.ws
 * @date 2024/4/30 16:06
 * @description 数据库策略枚举
 */
@Getter
@AllArgsConstructor
public enum DateBaseStrategyEnum {


    /**
     * mysql数据库
     */
    MYSQL("mysql", new MysqlBackupRestoreStrategy()),

    /**
     * 达梦数据库
     */
    DM("dm", new DmBackupRestoreStrategy()),

    /**
     * oceanBase数据库
     */
    OCEAN_BASE("oceanBase", new OceanBaseBackupRestoreStrategy());

    /**
     * 数据库类型
     */
    private final String databaseType;

    /**
     * 数据库备份恢复策略
     */
    private final BackupRestoreStrategy backupRestoreStrategy;


    /**
     * 根据数据库类型获取策略
     *
     * @param databaseType 数据库类型
     * @return 策略
     */
    public static DateBaseStrategyEnum getStrategy(String databaseType) {
        for (DateBaseStrategyEnum strategy : DateBaseStrategyEnum.values()) {
            if (strategy.getDatabaseType().equals(databaseType)) {
                return strategy;
            }
        }
        return MYSQL;
    }
}